﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ECCSystem.CheckClass
{
	public static class clsUICheck
	{
		#region "ChenkLen ：判断字符串是否超长"
		/// <summary>
		/// 判断字符串是否超长
		/// </summary>
		/// <param name="strContent"></param>
		/// <param name="intLen"></param>
		/// <returns></returns>
		public static bool CheckLen(string strContent,int intLen)
		{
			if (NullToString(strContent).Length > intLen)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		#endregion

		#region "NullToString : null变成空串"
		/// <summary>
		/// null变成空串
		/// </summary>
		/// <param name="objContent"></param>
		/// <returns></returns>
		public static string NullToString(object objContent)
		{
			if (objContent == null)
			{
				return "";
			}
			else
			{
				return objContent.ToString();
			}
		}
		#endregion

		#region "StringToNull : 空字符串转成null"
		/// <summary>
		/// 空字符串转成null
		/// </summary>
		/// <param name="strContent"></param>
		/// <returns></returns>
		public static string StringToNull(string strContent)
		{
			if (strContent == null)
			{
				return strContent;
			}
			else if (strContent.Trim() == "")
			{
				return null;
			}
			else
			{
				return null;
			}

		}
		#endregion

		#region "CheckFileExist : 文件是否存在判断"
		/// <summary>
		/// 文件是否存在判断
		/// </summary>
		/// <param name="strPath"></param>
		/// <param name="strFileName"></param>
		/// <returns></returns>
		public static bool CheckFileExist(string strPath, string strFileName)
		{
			return File.Exists(strPath + "\\" + strFileName);
		}
		#endregion

		#region "isNum : 半角数字チェック"
		/// <summary>
		/// 半角数字チェック
		/// </summary>
		/// <param name="str">判定文字列</param>
		/// <returns>true:数字 false:数字以外</returns>
		public static bool isNum(string str)
		{
			String sValid = "0123456789.";
			String sWork = str.ToLower();
			char[] chkChar = sWork.ToCharArray();

			for (int i = 0; i < chkChar.Length; i++)
			{
				if (sValid.IndexOf(chkChar[i]) < 0)
					return false;
			}
			return true;
		}
		#endregion

		#region "isHankaku :文字列が半角どうかの判定を行う"
		/// <summary>
		/// 文字列が半角どうかの判定を行う
		/// </summary>
		/// <param name="chkStr">判定文字列</param>
		/// <returns>true :半角文字列 false:半角文字列以外</returns>
		public static bool isHankaku(string chkStr)
		{
			char[] chkChar = chkStr.ToCharArray();
			//全角(65281-65374)
			for (int i = 0; i < chkChar.Length; i++)
			{
				//全角空格
				if (chkChar[i] == 12288)
				{
					return false;
				}
				if (chkChar[i] >= 65281 && chkChar[i] <= 65374)
				{
					return false;
				}
			}

			return true;
		}
		#endregion

		#region "isZenkaku : 文字列が全角どうかの判定を行う"
		/// <summary>
		/// 文字列が全角どうかの判定を行う
		/// </summary>
		/// <param name="chkStr">判定文字列</param>
		/// <returns>true :全角文字列 false:全角文字列以外</returns>
		public static bool isZenkaku(String chkStr)
		{
			char[] chkChar = chkStr.ToCharArray();
			//半角(32-126)
			for (int i = 0; i < chkChar.Length; i++)
			{
				if (chkChar[i] >= 32 && chkChar[i] <= 126)
				{
					return false;
				}
			}
			return true;
		}
		#endregion

		#region "CheckDate ：判断是否是日期"
		/// <summary>
		/// 判断是否是日期
		/// </summary>
		/// <param name="strContent"></param>
		/// <param name="intLen"></param>
		/// <returns></returns>
		public static bool CheckDate(object strContent)
		{
			try
			{
				Convert.ToDateTime(strContent);
				return true;
			}
			catch
			{
				return false;
			}
			
		}
		#endregion

	}
}
